class HeapOperator{
  upAdjust(array){
    let childIndex = array.length-1
    let parentIndex = Math.floor((childIndex-1)/2)
    let temp = array[childIndex]
    while(childIndex > 0 && temp < array[parentIndex]) {
      array[childIndex] = array[parentIndex]
      childIndex = parentIndex
      parentIndex = Math.floor((parentIndex - 1)/2)
    }
    array[childIndex] = temp
    return array
  }
  downAdjust(array, parentIndex, length) {
    let temp = parentIndex
    let childIndex = parentIndex * 2 +1
    while(childIndex < length) {
      if(childIndex + 1 < length && array[childIndex + 1] < array[childIndex]) {
        childIndex++
      }
      if(temp <= array[childIndex]) {
        break
      }
      array[parentIndex] = array[childIndex]
      parentIndex = childIndex
      childIndex = childIndex*2 + 1
    }
    array[parentIndex] = temp
  }
  buildHeap(array) {
    for(let i = (array.length-2)/2; i>0; i++){
      this.downAdjust(array, i, array.length)
    }
  }
}

let array = [1,3,2,6,5,7,8,9,10,0]
let ary = new HeapOperator().upAdjust(array)
console.log(ary)